{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1c5ee461",
   "metadata": {},
   "source": [
    "-------------\n",
    "* 本学习记录人：罗林胜\n",
    "* 学习时间:2021.10.28\n",
    "* week04\n",
    "* [参考的文本链接](https://www.python.org/doc/)\n",
    "\n",
    "--------------\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1b2ad51",
   "metadata": {},
   "source": [
    "\n",
    "# 本周学习内容\n",
    "\n",
    "## 1.字符串数值方法\n",
    "\n",
    "> 1.字符串（str）[序列类型](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)\n",
    ">> 1.字符串方法（举例）：\n",
    ">>> 1.str.capitalize( ) : 返回字符串的副本，其中第一个字符大写，其余字符小写。  \n",
    ">>> 2.name.center() :以长度为width的字符串为中心返回  \n",
    ">>> 3.str.isdigit() :返回True如果字符串中的所有字符是数字  \n",
    ">>> 4.  ...\n",
    "\n",
    "\n",
    "> 2.数值的[数据类型](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)  \n",
    "\n",
    "> 3.数值的类型  \n",
    ">> 1.int（整形）208  \n",
    ">>2.float(浮点型) 3.1415926  \n",
    ">>3.complex(复数) 2+3j  \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d992b3c8",
   "metadata": {},
   "source": [
    "# 字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ba9f9ee3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'luolinsheng'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name=\"luolinsheng\"\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9de90069",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Luolinsheng'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 变量.tab键\n",
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f3c50fda",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'                                            luolinsheng                                             '"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#居中\n",
    "name.center(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3703c975",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              luolinsheng                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               '"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.center(1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "8d7057f3",
   "metadata": {},
   "outputs": [],
   "source": [
    "text=\"http://localhost:8889/notebooks/week04%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%95%B0%E5%80%BC%E6%96%B9%E6%B3%95-%E6%B3%A8%E9%87%8A-%E7%94%A8%E6%88%B7%E8%BE%93%E5%85%A5.ipynb\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "aa1cbd21",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#检查某一个字符/字符串/出现次数（词频）\n",
    "text.count('week04')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "835a5513",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 判断字符串是否是数值，如果返回true 说明字符串\n",
    "text.isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "47702b37",
   "metadata": {},
   "outputs": [],
   "source": [
    "stud_id=\"2100001123\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1ae1cf61",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_id.isdigit()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "136e7dd6",
   "metadata": {},
   "source": [
    "###  \\n表示换行，\\t表示制表符\\r表示回车键"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6b97d09a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luolinsheng \n",
      " hello\n"
     ]
    }
   ],
   "source": [
    "print(\"luolinsheng\",'\\n','hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "09520a6e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "linsheng \n",
      " hello\n",
      "linsheng \t hello\n"
     ]
    }
   ],
   "source": [
    "print(\"linsheng\",'\\n','hello')\n",
    "print(\"linsheng\",'\\t','hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3db66b85",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luolinsheng \t hello\n"
     ]
    }
   ],
   "source": [
    "print(\"luolinsheng\",'\\t','hello')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "cbb9a434",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "luolinsheng \r",
      " hello\n"
     ]
    }
   ],
   "source": [
    "print(\"luolinsheng\",'\\r','hello')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "460d9725",
   "metadata": {},
   "source": [
    "### 数值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "b5cb51e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "#int\n",
    "classroom=208\n",
    "print(type(classroom))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "913a8e61",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'float'>\n"
     ]
    }
   ],
   "source": [
    "#float\n",
    "PI=3.1415926\n",
    "print(type(PI))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "27a58253",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "#complex\n",
    "complex_value=2+4j\n",
    "print(type(complex_value))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "4a877b12",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取整\n",
    "10//7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "bf62249a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取余（取模）\n",
    "10%7"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ba87013",
   "metadata": {},
   "source": [
    "* 额外知识点\n",
    "> 如何用一行代码抓取网站的表格"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "70b4b210",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "a552ec13",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Operation</th>\n",
       "      <th>Meaning</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>&lt;</td>\n",
       "      <td>strictly less than</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>&lt;=</td>\n",
       "      <td>less than or equal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>&gt;</td>\n",
       "      <td>strictly greater than</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>&gt;=</td>\n",
       "      <td>greater than or equal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>==</td>\n",
       "      <td>equal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>!=</td>\n",
       "      <td>not equal</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>is</td>\n",
       "      <td>object identity</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>is not</td>\n",
       "      <td>negated object identity</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Operation                  Meaning\n",
       "0         <       strictly less than\n",
       "1        <=       less than or equal\n",
       "2         >    strictly greater than\n",
       "3        >=    greater than or equal\n",
       "4        ==                    equal\n",
       "5        !=                not equal\n",
       "6        is          object identity\n",
       "7    is not  negated object identity"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取html页面的表格\n",
    "# 抓取页面所以的表格并按照顺序存储在[]里面.\n",
    "pd.read_html(\"https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex\") [1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "776bdf4f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Operation</th>\n",
       "      <th>Result</th>\n",
       "      <th>Notes</th>\n",
       "      <th>Full documentation</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>x + y</td>\n",
       "      <td>sum of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>x - y</td>\n",
       "      <td>difference of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>x * y</td>\n",
       "      <td>product of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>x / y</td>\n",
       "      <td>quotient of x and y</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>x // y</td>\n",
       "      <td>floored quotient of x and y</td>\n",
       "      <td>(1)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>x % y</td>\n",
       "      <td>remainder of x / y</td>\n",
       "      <td>(2)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>-x</td>\n",
       "      <td>x negated</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>+x</td>\n",
       "      <td>x unchanged</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>abs(x)</td>\n",
       "      <td>absolute value or magnitude of x</td>\n",
       "      <td>NaN</td>\n",
       "      <td>abs()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>int(x)</td>\n",
       "      <td>x converted to integer</td>\n",
       "      <td>(3)(6)</td>\n",
       "      <td>int()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>float(x)</td>\n",
       "      <td>x converted to floating point</td>\n",
       "      <td>(4)(6)</td>\n",
       "      <td>float()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>complex(re, im)</td>\n",
       "      <td>a complex number with real part re, imaginary ...</td>\n",
       "      <td>(6)</td>\n",
       "      <td>complex()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>c.conjugate()</td>\n",
       "      <td>conjugate of the complex number c</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>divmod(x, y)</td>\n",
       "      <td>the pair (x // y, x % y)</td>\n",
       "      <td>(2)</td>\n",
       "      <td>divmod()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>pow(x, y)</td>\n",
       "      <td>x to the power y</td>\n",
       "      <td>(5)</td>\n",
       "      <td>pow()</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>x ** y</td>\n",
       "      <td>x to the power y</td>\n",
       "      <td>(5)</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Operation                                             Result  \\\n",
       "0             x + y                                     sum of x and y   \n",
       "1             x - y                              difference of x and y   \n",
       "2             x * y                                 product of x and y   \n",
       "3             x / y                                quotient of x and y   \n",
       "4            x // y                        floored quotient of x and y   \n",
       "5             x % y                                 remainder of x / y   \n",
       "6                -x                                          x negated   \n",
       "7                +x                                        x unchanged   \n",
       "8            abs(x)                   absolute value or magnitude of x   \n",
       "9            int(x)                             x converted to integer   \n",
       "10         float(x)                      x converted to floating point   \n",
       "11  complex(re, im)  a complex number with real part re, imaginary ...   \n",
       "12    c.conjugate()                  conjugate of the complex number c   \n",
       "13     divmod(x, y)                           the pair (x // y, x % y)   \n",
       "14        pow(x, y)                                   x to the power y   \n",
       "15           x ** y                                   x to the power y   \n",
       "\n",
       "     Notes Full documentation  \n",
       "0      NaN                NaN  \n",
       "1      NaN                NaN  \n",
       "2      NaN                NaN  \n",
       "3      NaN                NaN  \n",
       "4      (1)                NaN  \n",
       "5      (2)                NaN  \n",
       "6      NaN                NaN  \n",
       "7      NaN                NaN  \n",
       "8      NaN              abs()  \n",
       "9   (3)(6)              int()  \n",
       "10  (4)(6)            float()  \n",
       "11     (6)          complex()  \n",
       "12     NaN                NaN  \n",
       "13     (2)           divmod()  \n",
       "14     (5)              pow()  \n",
       "15     (5)                NaN  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex\")[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "cd729fc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b0bc8d91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Flag</th>\n",
       "      <th>Meaning</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>'#'</td>\n",
       "      <td>The value conversion will use the “alternate f...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>'0'</td>\n",
       "      <td>The conversion will be zero padded for numeric...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>'-'</td>\n",
       "      <td>The converted value is left adjusted (override...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>' '</td>\n",
       "      <td>(a space) A blank should be left before a posi...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>'+'</td>\n",
       "      <td>A sign character ('+' or '-') will precede the...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Flag                                            Meaning\n",
       "0  '#'  The value conversion will use the “alternate f...\n",
       "1  '0'  The conversion will be zero padded for numeric...\n",
       "2  '-'  The converted value is left adjusted (override...\n",
       "3  ' '  (a space) A blank should be left before a posi...\n",
       "4  '+'  A sign character ('+' or '-') will precede the..."
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_html(\"https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex\")[8]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6f9c9aa9",
   "metadata": {},
   "source": [
    "### for 循环"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0ff4e061",
   "metadata": {},
   "source": [
    "> 1.[for循环](https://docs.python.org/3/tutorial/controlflow.html#for-statements)  \n",
    "> 2.[range](https://docs.python.org/3/tutorial/controlflow.html#the-range-function)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "0d47e9ad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h\n",
      "e\n",
      "l\n",
      "l\n",
      "o\n"
     ]
    }
   ],
   "source": [
    "# 循环遍历：每一个元素依次输出\n",
    "for i in\"hello\":\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "5e55789e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 自动生成一系列的数值，生成从0开始 每一个增加1的一系列数值\n",
    "# range()只有一个值：1.从0开始生成 这个值的个数的数值 2.起始值=0 终止值=5 步长=1(默认1)\n",
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "0497aa22",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "4cac3c41",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# range(5,10)  5:start(起始值)   10:stop(终止值) 步长=1(默认1)  生成stop-start个数值\n",
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b49b4232",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# range(0,10,2)  0:start(起始值)   10：stop(终止值) 2：steep(步长)\n",
    "list(range(0,10,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "1d898e2e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range (5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "c4144821",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n",
      "hello\n"
     ]
    }
   ],
   "source": [
    "for i in range (5):\n",
    "    print(\"hello\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "8dc4e731",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 实例：我想抓取某招聘网站所有关于前端开发工程师的数据\n",
    "#实例2：抓取广州南方学院的所有新闻\n",
    "\n",
    "# https://www.nfu.edu.cn/xxyw/index5.htm\n",
    "\n",
    "url_01=\"https://www.nfu.edu.cn/xxyw/index\"\n",
    "# ur1_02=0-96的数字\n",
    "url_03=\".htm\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "9d4e1d31",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/xxyw/index0.htm\n",
      "https://www.nfu.edu.cn/xxyw/index1.htm\n",
      "https://www.nfu.edu.cn/xxyw/index2.htm\n",
      "https://www.nfu.edu.cn/xxyw/index3.htm\n",
      "https://www.nfu.edu.cn/xxyw/index4.htm\n",
      "https://www.nfu.edu.cn/xxyw/index5.htm\n",
      "https://www.nfu.edu.cn/xxyw/index6.htm\n",
      "https://www.nfu.edu.cn/xxyw/index7.htm\n",
      "https://www.nfu.edu.cn/xxyw/index8.htm\n",
      "https://www.nfu.edu.cn/xxyw/index9.htm\n",
      "https://www.nfu.edu.cn/xxyw/index10.htm\n",
      "https://www.nfu.edu.cn/xxyw/index11.htm\n",
      "https://www.nfu.edu.cn/xxyw/index12.htm\n",
      "https://www.nfu.edu.cn/xxyw/index13.htm\n",
      "https://www.nfu.edu.cn/xxyw/index14.htm\n",
      "https://www.nfu.edu.cn/xxyw/index15.htm\n",
      "https://www.nfu.edu.cn/xxyw/index16.htm\n",
      "https://www.nfu.edu.cn/xxyw/index17.htm\n",
      "https://www.nfu.edu.cn/xxyw/index18.htm\n",
      "https://www.nfu.edu.cn/xxyw/index19.htm\n",
      "https://www.nfu.edu.cn/xxyw/index20.htm\n",
      "https://www.nfu.edu.cn/xxyw/index21.htm\n",
      "https://www.nfu.edu.cn/xxyw/index22.htm\n",
      "https://www.nfu.edu.cn/xxyw/index23.htm\n",
      "https://www.nfu.edu.cn/xxyw/index24.htm\n",
      "https://www.nfu.edu.cn/xxyw/index25.htm\n",
      "https://www.nfu.edu.cn/xxyw/index26.htm\n",
      "https://www.nfu.edu.cn/xxyw/index27.htm\n",
      "https://www.nfu.edu.cn/xxyw/index28.htm\n",
      "https://www.nfu.edu.cn/xxyw/index29.htm\n",
      "https://www.nfu.edu.cn/xxyw/index30.htm\n",
      "https://www.nfu.edu.cn/xxyw/index31.htm\n",
      "https://www.nfu.edu.cn/xxyw/index32.htm\n",
      "https://www.nfu.edu.cn/xxyw/index33.htm\n",
      "https://www.nfu.edu.cn/xxyw/index34.htm\n",
      "https://www.nfu.edu.cn/xxyw/index35.htm\n",
      "https://www.nfu.edu.cn/xxyw/index36.htm\n",
      "https://www.nfu.edu.cn/xxyw/index37.htm\n",
      "https://www.nfu.edu.cn/xxyw/index38.htm\n",
      "https://www.nfu.edu.cn/xxyw/index39.htm\n",
      "https://www.nfu.edu.cn/xxyw/index40.htm\n",
      "https://www.nfu.edu.cn/xxyw/index41.htm\n",
      "https://www.nfu.edu.cn/xxyw/index42.htm\n",
      "https://www.nfu.edu.cn/xxyw/index43.htm\n",
      "https://www.nfu.edu.cn/xxyw/index44.htm\n",
      "https://www.nfu.edu.cn/xxyw/index45.htm\n",
      "https://www.nfu.edu.cn/xxyw/index46.htm\n",
      "https://www.nfu.edu.cn/xxyw/index47.htm\n",
      "https://www.nfu.edu.cn/xxyw/index48.htm\n",
      "https://www.nfu.edu.cn/xxyw/index49.htm\n",
      "https://www.nfu.edu.cn/xxyw/index50.htm\n",
      "https://www.nfu.edu.cn/xxyw/index51.htm\n",
      "https://www.nfu.edu.cn/xxyw/index52.htm\n",
      "https://www.nfu.edu.cn/xxyw/index53.htm\n",
      "https://www.nfu.edu.cn/xxyw/index54.htm\n",
      "https://www.nfu.edu.cn/xxyw/index55.htm\n",
      "https://www.nfu.edu.cn/xxyw/index56.htm\n",
      "https://www.nfu.edu.cn/xxyw/index57.htm\n",
      "https://www.nfu.edu.cn/xxyw/index58.htm\n",
      "https://www.nfu.edu.cn/xxyw/index59.htm\n",
      "https://www.nfu.edu.cn/xxyw/index60.htm\n",
      "https://www.nfu.edu.cn/xxyw/index61.htm\n",
      "https://www.nfu.edu.cn/xxyw/index62.htm\n",
      "https://www.nfu.edu.cn/xxyw/index63.htm\n",
      "https://www.nfu.edu.cn/xxyw/index64.htm\n",
      "https://www.nfu.edu.cn/xxyw/index65.htm\n",
      "https://www.nfu.edu.cn/xxyw/index66.htm\n",
      "https://www.nfu.edu.cn/xxyw/index67.htm\n",
      "https://www.nfu.edu.cn/xxyw/index68.htm\n",
      "https://www.nfu.edu.cn/xxyw/index69.htm\n",
      "https://www.nfu.edu.cn/xxyw/index70.htm\n",
      "https://www.nfu.edu.cn/xxyw/index71.htm\n",
      "https://www.nfu.edu.cn/xxyw/index72.htm\n",
      "https://www.nfu.edu.cn/xxyw/index73.htm\n",
      "https://www.nfu.edu.cn/xxyw/index74.htm\n",
      "https://www.nfu.edu.cn/xxyw/index75.htm\n",
      "https://www.nfu.edu.cn/xxyw/index76.htm\n",
      "https://www.nfu.edu.cn/xxyw/index77.htm\n",
      "https://www.nfu.edu.cn/xxyw/index78.htm\n",
      "https://www.nfu.edu.cn/xxyw/index79.htm\n",
      "https://www.nfu.edu.cn/xxyw/index80.htm\n",
      "https://www.nfu.edu.cn/xxyw/index81.htm\n",
      "https://www.nfu.edu.cn/xxyw/index82.htm\n",
      "https://www.nfu.edu.cn/xxyw/index83.htm\n",
      "https://www.nfu.edu.cn/xxyw/index84.htm\n",
      "https://www.nfu.edu.cn/xxyw/index85.htm\n",
      "https://www.nfu.edu.cn/xxyw/index86.htm\n",
      "https://www.nfu.edu.cn/xxyw/index87.htm\n",
      "https://www.nfu.edu.cn/xxyw/index88.htm\n",
      "https://www.nfu.edu.cn/xxyw/index89.htm\n",
      "https://www.nfu.edu.cn/xxyw/index90.htm\n",
      "https://www.nfu.edu.cn/xxyw/index91.htm\n",
      "https://www.nfu.edu.cn/xxyw/index92.htm\n",
      "https://www.nfu.edu.cn/xxyw/index93.htm\n",
      "https://www.nfu.edu.cn/xxyw/index94.htm\n",
      "https://www.nfu.edu.cn/xxyw/index95.htm\n",
      "https://www.nfu.edu.cn/xxyw/index96.htm\n"
     ]
    }
   ],
   "source": [
    "for i in range (97):\n",
    "    #中间的操作过程，统一\n",
    "    if i == 0:\n",
    "        print(url_01+str(i)+url_03)   \n",
    "    else:\n",
    "        print(url_01+ str(i) +url_03)  \n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0d3b32f9",
   "metadata": {},
   "source": [
    "### for循环+range（）练习\n",
    ">1.random随机数实验[小视频](https://www.bilibili.com/video/BV18p4y167BEspm_id_from=333.999.0.0)  \n",
    ">2.课本P35小练习  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d44fcc23",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.random随机数实验\n",
    "import random #通用random模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "81614fc7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on module random:\n",
      "\n",
      "NAME\n",
      "    random - Random variable generators.\n",
      "\n",
      "MODULE REFERENCE\n",
      "    https://docs.python.org/3.8/library/random\n",
      "    \n",
      "    The following documentation is automatically generated from the Python\n",
      "    source files.  It may be incomplete, incorrect or include features that\n",
      "    are considered implementation detail and may vary between Python\n",
      "    implementations.  When in doubt, consult the module reference at the\n",
      "    location listed above.\n",
      "\n",
      "DESCRIPTION\n",
      "        integers\n",
      "        --------\n",
      "               uniform within range\n",
      "    \n",
      "        sequences\n",
      "        ---------\n",
      "               pick random element\n",
      "               pick random sample\n",
      "               pick weighted random sample\n",
      "               generate random permutation\n",
      "    \n",
      "        distributions on the real line:\n",
      "        ------------------------------\n",
      "               uniform\n",
      "               triangular\n",
      "               normal (Gaussian)\n",
      "               lognormal\n",
      "               negative exponential\n",
      "               gamma\n",
      "               beta\n",
      "               pareto\n",
      "               Weibull\n",
      "    \n",
      "        distributions on the circle (angles 0 to 2pi)\n",
      "        ---------------------------------------------\n",
      "               circular uniform\n",
      "               von Mises\n",
      "    \n",
      "    General notes on the underlying Mersenne Twister core generator:\n",
      "    \n",
      "    * The period is 2**19937-1.\n",
      "    * It is one of the most extensively tested generators in existence.\n",
      "    * The random() method is implemented in C, executes in a single Python step,\n",
      "      and is, therefore, threadsafe.\n",
      "\n",
      "CLASSES\n",
      "    _random.Random(builtins.object)\n",
      "        Random\n",
      "            SystemRandom\n",
      "    \n",
      "    class Random(_random.Random)\n",
      "     |  Random(x=None)\n",
      "     |  \n",
      "     |  Random number generator base class used by bound module functions.\n",
      "     |  \n",
      "     |  Used to instantiate instances of Random to get generators that don't\n",
      "     |  share state.\n",
      "     |  \n",
      "     |  Class Random can also be subclassed if you want to use a different basic\n",
      "     |  generator of your own devising: in that case, override the following\n",
      "     |  methods:  random(), seed(), getstate(), and setstate().\n",
      "     |  Optionally, implement a getrandbits() method so that randrange()\n",
      "     |  can cover arbitrarily large ranges.\n",
      "     |  \n",
      "     |  Method resolution order:\n",
      "     |      Random\n",
      "     |      _random.Random\n",
      "     |      builtins.object\n",
      "     |  \n",
      "     |  Methods defined here:\n",
      "     |  \n",
      "     |  __getstate__(self)\n",
      "     |      # Issue 17489: Since __reduce__ was defined to fix #759889 this is no\n",
      "     |      # longer called; we leave it here because it has been here since random was\n",
      "     |      # rewritten back in 2001 and why risk breaking something.\n",
      "     |  \n",
      "     |  __init__(self, x=None)\n",
      "     |      Initialize an instance.\n",
      "     |      \n",
      "     |      Optional argument x controls seeding, as for Random.seed().\n",
      "     |  \n",
      "     |  __reduce__(self)\n",
      "     |      Helper for pickle.\n",
      "     |  \n",
      "     |  __setstate__(self, state)\n",
      "     |  \n",
      "     |  betavariate(self, alpha, beta)\n",
      "     |      Beta distribution.\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      Returned values range between 0 and 1.\n",
      "     |  \n",
      "     |  choice(self, seq)\n",
      "     |      Choose a random element from a non-empty sequence.\n",
      "     |  \n",
      "     |  choices(self, population, weights=None, *, cum_weights=None, k=1)\n",
      "     |      Return a k sized list of population elements chosen with replacement.\n",
      "     |      \n",
      "     |      If the relative weights or cumulative weights are not specified,\n",
      "     |      the selections are made with equal probability.\n",
      "     |  \n",
      "     |  expovariate(self, lambd)\n",
      "     |      Exponential distribution.\n",
      "     |      \n",
      "     |      lambd is 1.0 divided by the desired mean.  It should be\n",
      "     |      nonzero.  (The parameter would be called \"lambda\", but that is\n",
      "     |      a reserved word in Python.)  Returned values range from 0 to\n",
      "     |      positive infinity if lambd is positive, and from negative\n",
      "     |      infinity to 0 if lambd is negative.\n",
      "     |  \n",
      "     |  gammavariate(self, alpha, beta)\n",
      "     |      Gamma distribution.  Not the gamma function!\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      \n",
      "     |      The probability distribution function is:\n",
      "     |      \n",
      "     |                  x ** (alpha - 1) * math.exp(-x / beta)\n",
      "     |        pdf(x) =  --------------------------------------\n",
      "     |                    math.gamma(alpha) * beta ** alpha\n",
      "     |  \n",
      "     |  gauss(self, mu, sigma)\n",
      "     |      Gaussian distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.  This is\n",
      "     |      slightly faster than the normalvariate() function.\n",
      "     |      \n",
      "     |      Not thread-safe without a lock around calls.\n",
      "     |  \n",
      "     |  getstate(self)\n",
      "     |      Return internal state; can be passed to setstate() later.\n",
      "     |  \n",
      "     |  lognormvariate(self, mu, sigma)\n",
      "     |      Log normal distribution.\n",
      "     |      \n",
      "     |      If you take the natural logarithm of this distribution, you'll get a\n",
      "     |      normal distribution with mean mu and standard deviation sigma.\n",
      "     |      mu can have any value, and sigma must be greater than zero.\n",
      "     |  \n",
      "     |  normalvariate(self, mu, sigma)\n",
      "     |      Normal distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.\n",
      "     |  \n",
      "     |  paretovariate(self, alpha)\n",
      "     |      Pareto distribution.  alpha is the shape parameter.\n",
      "     |  \n",
      "     |  randint(self, a, b)\n",
      "     |      Return random integer in range [a, b], including both end points.\n",
      "     |  \n",
      "     |  randrange(self, start, stop=None, step=1, _int=<class 'int'>)\n",
      "     |      Choose a random item from range(start, stop[, step]).\n",
      "     |      \n",
      "     |      This fixes the problem with randint() which includes the\n",
      "     |      endpoint; in Python this is usually not what you want.\n",
      "     |  \n",
      "     |  sample(self, population, k)\n",
      "     |      Chooses k unique random elements from a population sequence or set.\n",
      "     |      \n",
      "     |      Returns a new list containing elements from the population while\n",
      "     |      leaving the original population unchanged.  The resulting list is\n",
      "     |      in selection order so that all sub-slices will also be valid random\n",
      "     |      samples.  This allows raffle winners (the sample) to be partitioned\n",
      "     |      into grand prize and second place winners (the subslices).\n",
      "     |      \n",
      "     |      Members of the population need not be hashable or unique.  If the\n",
      "     |      population contains repeats, then each occurrence is a possible\n",
      "     |      selection in the sample.\n",
      "     |      \n",
      "     |      To choose a sample in a range of integers, use range as an argument.\n",
      "     |      This is especially fast and space efficient for sampling from a\n",
      "     |      large population:   sample(range(10000000), 60)\n",
      "     |  \n",
      "     |  seed(self, a=None, version=2)\n",
      "     |      Initialize internal state from hashable object.\n",
      "     |      \n",
      "     |      None or no argument seeds from current time or from an operating\n",
      "     |      system specific randomness source if available.\n",
      "     |      \n",
      "     |      If *a* is an int, all bits are used.\n",
      "     |      \n",
      "     |      For version 2 (the default), all of the bits are used if *a* is a str,\n",
      "     |      bytes, or bytearray.  For version 1 (provided for reproducing random\n",
      "     |      sequences from older versions of Python), the algorithm for str and\n",
      "     |      bytes generates a narrower range of seeds.\n",
      "     |  \n",
      "     |  setstate(self, state)\n",
      "     |      Restore internal state from object returned by getstate().\n",
      "     |  \n",
      "     |  shuffle(self, x, random=None)\n",
      "     |      Shuffle list x in place, and return None.\n",
      "     |      \n",
      "     |      Optional argument random is a 0-argument function returning a\n",
      "     |      random float in [0.0, 1.0); if it is the default None, the\n",
      "     |      standard random.random will be used.\n",
      "     |  \n",
      "     |  triangular(self, low=0.0, high=1.0, mode=None)\n",
      "     |      Triangular distribution.\n",
      "     |      \n",
      "     |      Continuous distribution bounded by given lower and upper limits,\n",
      "     |      and having a given mode value in-between.\n",
      "     |      \n",
      "     |      http://en.wikipedia.org/wiki/Triangular_distribution\n",
      "     |  \n",
      "     |  uniform(self, a, b)\n",
      "     |      Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
      "     |  \n",
      "     |  vonmisesvariate(self, mu, kappa)\n",
      "     |      Circular data distribution.\n",
      "     |      \n",
      "     |      mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
      "     |      kappa is the concentration parameter, which must be greater than or\n",
      "     |      equal to zero.  If kappa is equal to zero, this distribution reduces\n",
      "     |      to a uniform random angle over the range 0 to 2*pi.\n",
      "     |  \n",
      "     |  weibullvariate(self, alpha, beta)\n",
      "     |      Weibull distribution.\n",
      "     |      \n",
      "     |      alpha is the scale parameter and beta is the shape parameter.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Class methods defined here:\n",
      "     |  \n",
      "     |  __init_subclass__(**kwargs) from builtins.type\n",
      "     |      Control how subclasses generate random integers.\n",
      "     |      \n",
      "     |      The algorithm a subclass can use depends on the random() and/or\n",
      "     |      getrandbits() implementation available to it and determines\n",
      "     |      whether it can generate random integers from arbitrarily large\n",
      "     |      ranges.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data descriptors defined here:\n",
      "     |  \n",
      "     |  __dict__\n",
      "     |      dictionary for instance variables (if defined)\n",
      "     |  \n",
      "     |  __weakref__\n",
      "     |      list of weak references to the object (if defined)\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data and other attributes defined here:\n",
      "     |  \n",
      "     |  VERSION = 3\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from _random.Random:\n",
      "     |  \n",
      "     |  __getattribute__(self, name, /)\n",
      "     |      Return getattr(self, name).\n",
      "     |  \n",
      "     |  getrandbits(self, k, /)\n",
      "     |      getrandbits(k) -> x.  Generates an int with k random bits.\n",
      "     |  \n",
      "     |  random(self, /)\n",
      "     |      random() -> x in the interval [0, 1).\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Static methods inherited from _random.Random:\n",
      "     |  \n",
      "     |  __new__(*args, **kwargs) from builtins.type\n",
      "     |      Create and return a new object.  See help(type) for accurate signature.\n",
      "    \n",
      "    class SystemRandom(Random)\n",
      "     |  SystemRandom(x=None)\n",
      "     |  \n",
      "     |  Alternate random number generator using sources provided\n",
      "     |  by the operating system (such as /dev/urandom on Unix or\n",
      "     |  CryptGenRandom on Windows).\n",
      "     |  \n",
      "     |   Not available on all systems (see os.urandom() for details).\n",
      "     |  \n",
      "     |  Method resolution order:\n",
      "     |      SystemRandom\n",
      "     |      Random\n",
      "     |      _random.Random\n",
      "     |      builtins.object\n",
      "     |  \n",
      "     |  Methods defined here:\n",
      "     |  \n",
      "     |  getrandbits(self, k)\n",
      "     |      getrandbits(k) -> x.  Generates an int with k random bits.\n",
      "     |  \n",
      "     |  getstate = _notimplemented(self, *args, **kwds)\n",
      "     |  \n",
      "     |  random(self)\n",
      "     |      Get the next random number in the range [0.0, 1.0).\n",
      "     |  \n",
      "     |  seed(self, *args, **kwds)\n",
      "     |      Stub method.  Not used for a system random number generator.\n",
      "     |  \n",
      "     |  setstate = _notimplemented(self, *args, **kwds)\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from Random:\n",
      "     |  \n",
      "     |  __getstate__(self)\n",
      "     |      # Issue 17489: Since __reduce__ was defined to fix #759889 this is no\n",
      "     |      # longer called; we leave it here because it has been here since random was\n",
      "     |      # rewritten back in 2001 and why risk breaking something.\n",
      "     |  \n",
      "     |  __init__(self, x=None)\n",
      "     |      Initialize an instance.\n",
      "     |      \n",
      "     |      Optional argument x controls seeding, as for Random.seed().\n",
      "     |  \n",
      "     |  __reduce__(self)\n",
      "     |      Helper for pickle.\n",
      "     |  \n",
      "     |  __setstate__(self, state)\n",
      "     |  \n",
      "     |  betavariate(self, alpha, beta)\n",
      "     |      Beta distribution.\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      Returned values range between 0 and 1.\n",
      "     |  \n",
      "     |  choice(self, seq)\n",
      "     |      Choose a random element from a non-empty sequence.\n",
      "     |  \n",
      "     |  choices(self, population, weights=None, *, cum_weights=None, k=1)\n",
      "     |      Return a k sized list of population elements chosen with replacement.\n",
      "     |      \n",
      "     |      If the relative weights or cumulative weights are not specified,\n",
      "     |      the selections are made with equal probability.\n",
      "     |  \n",
      "     |  expovariate(self, lambd)\n",
      "     |      Exponential distribution.\n",
      "     |      \n",
      "     |      lambd is 1.0 divided by the desired mean.  It should be\n",
      "     |      nonzero.  (The parameter would be called \"lambda\", but that is\n",
      "     |      a reserved word in Python.)  Returned values range from 0 to\n",
      "     |      positive infinity if lambd is positive, and from negative\n",
      "     |      infinity to 0 if lambd is negative.\n",
      "     |  \n",
      "     |  gammavariate(self, alpha, beta)\n",
      "     |      Gamma distribution.  Not the gamma function!\n",
      "     |      \n",
      "     |      Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "     |      \n",
      "     |      The probability distribution function is:\n",
      "     |      \n",
      "     |                  x ** (alpha - 1) * math.exp(-x / beta)\n",
      "     |        pdf(x) =  --------------------------------------\n",
      "     |                    math.gamma(alpha) * beta ** alpha\n",
      "     |  \n",
      "     |  gauss(self, mu, sigma)\n",
      "     |      Gaussian distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.  This is\n",
      "     |      slightly faster than the normalvariate() function.\n",
      "     |      \n",
      "     |      Not thread-safe without a lock around calls.\n",
      "     |  \n",
      "     |  lognormvariate(self, mu, sigma)\n",
      "     |      Log normal distribution.\n",
      "     |      \n",
      "     |      If you take the natural logarithm of this distribution, you'll get a\n",
      "     |      normal distribution with mean mu and standard deviation sigma.\n",
      "     |      mu can have any value, and sigma must be greater than zero.\n",
      "     |  \n",
      "     |  normalvariate(self, mu, sigma)\n",
      "     |      Normal distribution.\n",
      "     |      \n",
      "     |      mu is the mean, and sigma is the standard deviation.\n",
      "     |  \n",
      "     |  paretovariate(self, alpha)\n",
      "     |      Pareto distribution.  alpha is the shape parameter.\n",
      "     |  \n",
      "     |  randint(self, a, b)\n",
      "     |      Return random integer in range [a, b], including both end points.\n",
      "     |  \n",
      "     |  randrange(self, start, stop=None, step=1, _int=<class 'int'>)\n",
      "     |      Choose a random item from range(start, stop[, step]).\n",
      "     |      \n",
      "     |      This fixes the problem with randint() which includes the\n",
      "     |      endpoint; in Python this is usually not what you want.\n",
      "     |  \n",
      "     |  sample(self, population, k)\n",
      "     |      Chooses k unique random elements from a population sequence or set.\n",
      "     |      \n",
      "     |      Returns a new list containing elements from the population while\n",
      "     |      leaving the original population unchanged.  The resulting list is\n",
      "     |      in selection order so that all sub-slices will also be valid random\n",
      "     |      samples.  This allows raffle winners (the sample) to be partitioned\n",
      "     |      into grand prize and second place winners (the subslices).\n",
      "     |      \n",
      "     |      Members of the population need not be hashable or unique.  If the\n",
      "     |      population contains repeats, then each occurrence is a possible\n",
      "     |      selection in the sample.\n",
      "     |      \n",
      "     |      To choose a sample in a range of integers, use range as an argument.\n",
      "     |      This is especially fast and space efficient for sampling from a\n",
      "     |      large population:   sample(range(10000000), 60)\n",
      "     |  \n",
      "     |  shuffle(self, x, random=None)\n",
      "     |      Shuffle list x in place, and return None.\n",
      "     |      \n",
      "     |      Optional argument random is a 0-argument function returning a\n",
      "     |      random float in [0.0, 1.0); if it is the default None, the\n",
      "     |      standard random.random will be used.\n",
      "     |  \n",
      "     |  triangular(self, low=0.0, high=1.0, mode=None)\n",
      "     |      Triangular distribution.\n",
      "     |      \n",
      "     |      Continuous distribution bounded by given lower and upper limits,\n",
      "     |      and having a given mode value in-between.\n",
      "     |      \n",
      "     |      http://en.wikipedia.org/wiki/Triangular_distribution\n",
      "     |  \n",
      "     |  uniform(self, a, b)\n",
      "     |      Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
      "     |  \n",
      "     |  vonmisesvariate(self, mu, kappa)\n",
      "     |      Circular data distribution.\n",
      "     |      \n",
      "     |      mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
      "     |      kappa is the concentration parameter, which must be greater than or\n",
      "     |      equal to zero.  If kappa is equal to zero, this distribution reduces\n",
      "     |      to a uniform random angle over the range 0 to 2*pi.\n",
      "     |  \n",
      "     |  weibullvariate(self, alpha, beta)\n",
      "     |      Weibull distribution.\n",
      "     |      \n",
      "     |      alpha is the scale parameter and beta is the shape parameter.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Class methods inherited from Random:\n",
      "     |  \n",
      "     |  __init_subclass__(**kwargs) from builtins.type\n",
      "     |      Control how subclasses generate random integers.\n",
      "     |      \n",
      "     |      The algorithm a subclass can use depends on the random() and/or\n",
      "     |      getrandbits() implementation available to it and determines\n",
      "     |      whether it can generate random integers from arbitrarily large\n",
      "     |      ranges.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data descriptors inherited from Random:\n",
      "     |  \n",
      "     |  __dict__\n",
      "     |      dictionary for instance variables (if defined)\n",
      "     |  \n",
      "     |  __weakref__\n",
      "     |      list of weak references to the object (if defined)\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data and other attributes inherited from Random:\n",
      "     |  \n",
      "     |  VERSION = 3\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from _random.Random:\n",
      "     |  \n",
      "     |  __getattribute__(self, name, /)\n",
      "     |      Return getattr(self, name).\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Static methods inherited from _random.Random:\n",
      "     |  \n",
      "     |  __new__(*args, **kwargs) from builtins.type\n",
      "     |      Create and return a new object.  See help(type) for accurate signature.\n",
      "\n",
      "FUNCTIONS\n",
      "    betavariate(alpha, beta) method of Random instance\n",
      "        Beta distribution.\n",
      "        \n",
      "        Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "        Returned values range between 0 and 1.\n",
      "    \n",
      "    choice(seq) method of Random instance\n",
      "        Choose a random element from a non-empty sequence.\n",
      "    \n",
      "    choices(population, weights=None, *, cum_weights=None, k=1) method of Random instance\n",
      "        Return a k sized list of population elements chosen with replacement.\n",
      "        \n",
      "        If the relative weights or cumulative weights are not specified,\n",
      "        the selections are made with equal probability.\n",
      "    \n",
      "    expovariate(lambd) method of Random instance\n",
      "        Exponential distribution.\n",
      "        \n",
      "        lambd is 1.0 divided by the desired mean.  It should be\n",
      "        nonzero.  (The parameter would be called \"lambda\", but that is\n",
      "        a reserved word in Python.)  Returned values range from 0 to\n",
      "        positive infinity if lambd is positive, and from negative\n",
      "        infinity to 0 if lambd is negative.\n",
      "    \n",
      "    gammavariate(alpha, beta) method of Random instance\n",
      "        Gamma distribution.  Not the gamma function!\n",
      "        \n",
      "        Conditions on the parameters are alpha > 0 and beta > 0.\n",
      "        \n",
      "        The probability distribution function is:\n",
      "        \n",
      "                    x ** (alpha - 1) * math.exp(-x / beta)\n",
      "          pdf(x) =  --------------------------------------\n",
      "                      math.gamma(alpha) * beta ** alpha\n",
      "    \n",
      "    gauss(mu, sigma) method of Random instance\n",
      "        Gaussian distribution.\n",
      "        \n",
      "        mu is the mean, and sigma is the standard deviation.  This is\n",
      "        slightly faster than the normalvariate() function.\n",
      "        \n",
      "        Not thread-safe without a lock around calls.\n",
      "    \n",
      "    getrandbits(k, /) method of Random instance\n",
      "        getrandbits(k) -> x.  Generates an int with k random bits.\n",
      "    \n",
      "    getstate() method of Random instance\n",
      "        Return internal state; can be passed to setstate() later.\n",
      "    \n",
      "    lognormvariate(mu, sigma) method of Random instance\n",
      "        Log normal distribution.\n",
      "        \n",
      "        If you take the natural logarithm of this distribution, you'll get a\n",
      "        normal distribution with mean mu and standard deviation sigma.\n",
      "        mu can have any value, and sigma must be greater than zero.\n",
      "    \n",
      "    normalvariate(mu, sigma) method of Random instance\n",
      "        Normal distribution.\n",
      "        \n",
      "        mu is the mean, and sigma is the standard deviation.\n",
      "    \n",
      "    paretovariate(alpha) method of Random instance\n",
      "        Pareto distribution.  alpha is the shape parameter.\n",
      "    \n",
      "    randint(a, b) method of Random instance\n",
      "        Return random integer in range [a, b], including both end points.\n",
      "    \n",
      "    random() method of Random instance\n",
      "        random() -> x in the interval [0, 1).\n",
      "    \n",
      "    randrange(start, stop=None, step=1, _int=<class 'int'>) method of Random instance\n",
      "        Choose a random item from range(start, stop[, step]).\n",
      "        \n",
      "        This fixes the problem with randint() which includes the\n",
      "        endpoint; in Python this is usually not what you want.\n",
      "    \n",
      "    sample(population, k) method of Random instance\n",
      "        Chooses k unique random elements from a population sequence or set.\n",
      "        \n",
      "        Returns a new list containing elements from the population while\n",
      "        leaving the original population unchanged.  The resulting list is\n",
      "        in selection order so that all sub-slices will also be valid random\n",
      "        samples.  This allows raffle winners (the sample) to be partitioned\n",
      "        into grand prize and second place winners (the subslices).\n",
      "        \n",
      "        Members of the population need not be hashable or unique.  If the\n",
      "        population contains repeats, then each occurrence is a possible\n",
      "        selection in the sample.\n",
      "        \n",
      "        To choose a sample in a range of integers, use range as an argument.\n",
      "        This is especially fast and space efficient for sampling from a\n",
      "        large population:   sample(range(10000000), 60)\n",
      "    \n",
      "    seed(a=None, version=2) method of Random instance\n",
      "        Initialize internal state from hashable object.\n",
      "        \n",
      "        None or no argument seeds from current time or from an operating\n",
      "        system specific randomness source if available.\n",
      "        \n",
      "        If *a* is an int, all bits are used.\n",
      "        \n",
      "        For version 2 (the default), all of the bits are used if *a* is a str,\n",
      "        bytes, or bytearray.  For version 1 (provided for reproducing random\n",
      "        sequences from older versions of Python), the algorithm for str and\n",
      "        bytes generates a narrower range of seeds.\n",
      "    \n",
      "    setstate(state) method of Random instance\n",
      "        Restore internal state from object returned by getstate().\n",
      "    \n",
      "    shuffle(x, random=None) method of Random instance\n",
      "        Shuffle list x in place, and return None.\n",
      "        \n",
      "        Optional argument random is a 0-argument function returning a\n",
      "        random float in [0.0, 1.0); if it is the default None, the\n",
      "        standard random.random will be used.\n",
      "    \n",
      "    triangular(low=0.0, high=1.0, mode=None) method of Random instance\n",
      "        Triangular distribution.\n",
      "        \n",
      "        Continuous distribution bounded by given lower and upper limits,\n",
      "        and having a given mode value in-between.\n",
      "        \n",
      "        http://en.wikipedia.org/wiki/Triangular_distribution\n",
      "    \n",
      "    uniform(a, b) method of Random instance\n",
      "        Get a random number in the range [a, b) or [a, b] depending on rounding.\n",
      "    \n",
      "    vonmisesvariate(mu, kappa) method of Random instance\n",
      "        Circular data distribution.\n",
      "        \n",
      "        mu is the mean angle, expressed in radians between 0 and 2*pi, and\n",
      "        kappa is the concentration parameter, which must be greater than or\n",
      "        equal to zero.  If kappa is equal to zero, this distribution reduces\n",
      "        to a uniform random angle over the range 0 to 2*pi.\n",
      "    \n",
      "    weibullvariate(alpha, beta) method of Random instance\n",
      "        Weibull distribution.\n",
      "        \n",
      "        alpha is the scale parameter and beta is the shape parameter.\n",
      "\n",
      "DATA\n",
      "    __all__ = ['Random', 'seed', 'random', 'uniform', 'randint', 'choice',...\n",
      "\n",
      "FILE\n",
      "    c:\\users\\linsheng\\anaconda3\\lib\\random.py\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ee0c1e58",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12\n",
      "8\n",
      "25\n",
      "1\n",
      "48\n",
      "21\n",
      "62\n",
      "50\n",
      "89\n",
      "79\n"
     ]
    }
   ],
   "source": [
    "  for i in range (10):\n",
    "        print(round(random.random()*100))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "58633c7e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "1\n",
      "6\n",
      "6\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "for i in range (5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "3a7feb6d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "2\n",
      "4\n",
      "2\n",
      "2\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(6):\n",
    "    print(random.randint(2,7))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "id": "c15cd127",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "4\n",
      "6\n",
      "4\n",
      "6\n",
      "6\n",
      "3\n",
      "1\n",
      "6\n"
     ]
    }
   ],
   "source": [
    "for i in range (10):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9cc2ca85",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'张泽峰'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " random.choice([\"罗林胜\",\"颜俊诺\",\"曾锦东\",\"张泽峰\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e0c39581",
   "metadata": {},
   "source": [
    "## 课本练习p35\n",
    "\n",
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "89fc227a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This second seems a little odd.\n",
      "Not an odd second.\n",
      "Not an odd second.\n",
      "Not an odd second.\n",
      "Not an odd second.\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    right_this_second = datetime.today().second\n",
    "\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    time.sleep(wait_time)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "42fd0fb5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--------------------\n",
      " 当前的时间秒数： 23\n",
      "This second seems a little odd.\n",
      "本次等待时间随机数： 1\n",
      "--------------------\n",
      " 当前的时间秒数： 24\n",
      "Not an odd second.\n",
      "本次等待时间随机数： 1\n",
      "--------------------\n",
      " 当前的时间秒数： 25\n",
      "This second seems a little odd.\n",
      "本次等待时间随机数： 3\n",
      "--------------------\n",
      " 当前的时间秒数： 28\n",
      "Not an odd second.\n",
      "本次等待时间随机数： 1\n",
      "--------------------\n",
      " 当前的时间秒数： 29\n",
      "This second seems a little odd.\n",
      "本次等待时间随机数： 1\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    # for + range 决定了 for循环过程（只要是和for有一个Tab键距离的代码块）的次数\n",
    "    right_this_second = datetime.today().second\n",
    "    # 使用datetime模块取获取当前时间节点的秒钟数值：datetime.today().second\n",
    "    \n",
    "    print(\"--------------------\\n 当前的时间秒数：\",right_this_second)\n",
    "    \n",
    "    \n",
    "    if right_this_second in odds:\n",
    "        # 判断 秒数是否是奇数（是否在odds列表中）\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    # 设置随机时间（1,5）数值\n",
    "    wait_time = random.randint(1,7)\n",
    "    \n",
    "    print(\"本次等待时间随机数：\",wait_time)\n",
    "    \n",
    "    # 随机数 + time.sleep(随机数) 决定每一次（一共5次）停留的时间\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "58063b6e",
   "metadata": {},
   "source": [
    "## 3.注释\n",
    " **注释的内容，代码不执行，直接忽略\n",
    "> 1.单行注释： #  \n",
    "> 2.多行注释： \"\"\" \"\"\"  \n",
    "> 3.注释的意义：  \n",
    ">> 1.记录代码的意义，非常必要，一个优秀的程序员/编程人员 是有良好的笔记记录和注释记录的习惯的。  \n",
    ">> 2.可以忽略一些不希望执行的代码  \n",
    ">> 3.可了解PEP8 国际标准\n",
    "  \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d3f897f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 全部+ # 快捷键 ： ctrl + /\n",
    "\n",
    "\n",
    "# import random\n",
    "# wait_time = random.randint(1,60)\n",
    "# print(wait_time)\n",
    "\n",
    "# word = \"bottles\"\n",
    "# print(word)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "d6552117",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n"
     ]
    }
   ],
   "source": [
    "\"\"\"\n",
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait_time)\n",
    "\n",
    "word = \"bottles\"\n",
    "print(word)\n",
    "\"\"\"\n",
    "\n",
    "print(\"hello\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "0c5cfc18",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "57\n",
      "bottles\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import random\n",
    "wait_time = random.randint(1,60)\n",
    "print(wait_time)\n",
    "\n",
    "word = \"bottles\"\n",
    "print(word)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd30a7b6",
   "metadata": {},
   "source": [
    "# 啤酒童谣练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "016cb0ec",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "90 bottles of beer on the wall.\n",
      "90 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "89 bottles of beer on the wall.\n",
      "89 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "88 bottles of beer on the wall.\n",
      "88 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "87 bottles of beer on the wall.\n",
      "87 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "86 bottles of beer on the wall.\n",
      "86 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "85 bottles of beer on the wall.\n",
      "85 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "84 bottles of beer on the wall.\n",
      "84 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "83 bottles of beer on the wall.\n",
      "83 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "82 bottles of beer on the wall.\n",
      "82 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "81 bottles of beer on the wall.\n",
      "81 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "80 bottles of beer on the wall.\n",
      "80 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "79 bottles of beer on the wall.\n",
      "79 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "78 bottles of beer on the wall.\n",
      "78 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "77 bottles of beer on the wall.\n",
      "77 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "76 bottles of beer on the wall.\n",
      "76 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "75 bottles of beer on the wall.\n",
      "75 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "74 bottles of beer on the wall.\n",
      "74 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "73 bottles of beer on the wall.\n",
      "73 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "72 bottles of beer on the wall.\n",
      "72 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "71 bottles of beer on the wall.\n",
      "71 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "70 bottles of beer on the wall.\n",
      "70 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "69 bottles of beer on the wall.\n",
      "69 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "68 bottles of beer on the wall.\n",
      "68 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "67 bottles of beer on the wall.\n",
      "67 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "66 bottles of beer on the wall.\n",
      "66 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "65 bottles of beer on the wall.\n",
      "65 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "64 bottles of beer on the wall.\n",
      "64 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "63 bottles of beer on the wall.\n",
      "63 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "62 bottles of beer on the wall.\n",
      "62 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "61 bottles of beer on the wall.\n",
      "61 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "60 bottles of beer on the wall.\n",
      "60 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "59 bottles of beer on the wall.\n",
      "59 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "58 bottles of beer on the wall.\n",
      "58 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "57 bottles of beer on the wall.\n",
      "57 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "56 bottles of beer on the wall.\n",
      "56 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "55 bottles of beer on the wall.\n",
      "55 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "54 bottles of beer on the wall.\n",
      "54 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "53 bottles of beer on the wall.\n",
      "53 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "52 bottles of beer on the wall.\n",
      "52 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "51 bottles of beer on the wall.\n",
      "51 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "50 bottles of beer on the wall.\n",
      "50 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "49 bottles of beer on the wall.\n",
      "49 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "48 bottles of beer on the wall.\n",
      "48 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "47 bottles of beer on the wall.\n",
      "47 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "46 bottles of beer on the wall.\n",
      "46 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "45 bottles of beer on the wall.\n",
      "45 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "44 bottles of beer on the wall.\n",
      "44 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "43 bottles of beer on the wall.\n",
      "43 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "42 bottles of beer on the wall.\n",
      "42 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "41 bottles of beer on the wall.\n",
      "41 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "40 bottles of beer on the wall.\n",
      "40 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "39 bottles of beer on the wall.\n",
      "39 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "38 bottles of beer on the wall.\n",
      "38 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "37 bottles of beer on the wall.\n",
      "37 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "36 bottles of beer on the wall.\n",
      "36 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "35 bottles of beer on the wall.\n",
      "35 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "34 bottles of beer on the wall.\n",
      "34 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "33 bottles of beer on the wall.\n",
      "33 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "32 bottles of beer on the wall.\n",
      "32 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "31 bottles of beer on the wall.\n",
      "31 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "30 bottles of beer on the wall.\n",
      "30 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "29 bottles of beer on the wall.\n",
      "29 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "28 bottles of beer on the wall.\n",
      "28 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "27 bottles of beer on the wall.\n",
      "27 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "26 bottles of beer on the wall.\n",
      "26 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "25 bottles of beer on the wall.\n",
      "25 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "24 bottles of beer on the wall.\n",
      "24 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "23 bottles of beer on the wall.\n",
      "23 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "22 bottles of beer on the wall.\n",
      "22 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "21 bottles of beer on the wall.\n",
      "21 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "20 bottles of beer on the wall.\n",
      "20 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "19 bottles of beer on the wall.\n",
      "19 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "18 bottles of beer on the wall.\n",
      "18 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "17 bottles of beer on the wall.\n",
      "17 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "16 bottles of beer on the wall.\n",
      "16 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "15 bottles of beer on the wall.\n",
      "15 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "14 bottles of beer on the wall.\n",
      "14 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "13 bottles of beer on the wall.\n",
      "13 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "12 bottles of beer on the wall.\n",
      "12 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "11 bottles of beer on the wall.\n",
      "11 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "10 bottles of beer on the wall.\n",
      "10 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "9 bottles of beer on the wall.\n",
      "9 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "8 bottles of beer on the wall.\n",
      "8 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "7 bottles of beer on the wall.\n",
      "7 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "6 bottles of beer on the wall.\n",
      "6 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "5 bottles of beer on the wall.\n",
      "5 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "4 bottles of beer on the wall.\n",
      "4 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "3 bottles of beer on the wall.\n",
      "3 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "2 bottles of beer on the wall.\n",
      "2 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "1 bottles of beer on the wall.\n",
      "1 bottles of beer.\n",
      "Take on down.\n",
      "Pass it around.\n",
      "No more bottles of beer on the wall.\n"
     ]
    },
    {
     "ename": "NameError",
     "evalue": "name 'new_num' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-13-2fe98bc96b9d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     19\u001b[0m     \u001b[0mnew_num\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mbeer_num\u001b[0m \u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     20\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mnew_num\u001b[0m\u001b[1;33m==\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     22\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     23\u001b[0m     \u001b[0mword\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"bottle\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'new_num' is not defined"
     ]
    }
   ],
   "source": [
    "word=\"bottles\"\n",
    "\n",
    "for beer_num in range(90,0,-1):\n",
    "    \n",
    "    print(beer_num,word,\"of beer on the wall.\")\n",
    "\n",
    "    print(beer_num,word,\"of beer.\")\n",
    "\n",
    "    print(\"Take on down.\")\n",
    "\n",
    "    print(\"Pass it around.\")\n",
    "\n",
    "if beer_num==1:\n",
    "        \n",
    "    print(\"No more bottles of beer on the wall.\")\n",
    "    \n",
    "else:\n",
    "    \n",
    "    new_num=beer_num -1\n",
    "    \n",
    "if new_num==1:\n",
    "    \n",
    "    word=\"bottle\"\n",
    "    \n",
    "    print(new_num,word,\"of beer on the wall\")\n",
    "    \n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17f41a5c",
   "metadata": {},
   "outputs": [],
   "source": [
    " "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
